
**************************************************************************************************;
**************************************************************************************************;
*This do file generates the following set of tables:
*Table 1: Authoritarian Parenting and Peer Environment within Schools;
*Appendix Table A-3: Authoritarian Parenting and Peer Environment within Schools (Gini)
*Appendix Table A-4: Authoritarian Parenting and Peer Environment within Schools (by Gender);
*Appendix Table A-5: Authoritarian Parenting (Index) and Peer Environment within Schools
**************************************************************************************************;
**************************************************************************************************;


*Set of controls for the regression models;
global controls "i.gender i.race age educ_mother_miss d_educ_mother_miss family_income_miss d_family_income_miss "

*Open data;
use $scratch/final_skills_peers.dta, clear
gen ar=.
replace ar=0 if important_boy_learn !=.
replace ar=1 if important_boy_learn ==1

* important_boy_learn ==1 is "to work hard" 
gen av=.
replace av=0 if important_boy_learn!=.
replace av=1 if important_boy_learn==4
 
gen pe=.
replace pe=0 if ar==1 | av==1
replace pe=1 if ar==0 & av==0
 
*Multinomial dummy
gen par_sty=1 if pe==1
replace par_sty=2 if av==1
replace par_sty=3 if ar==1

tab par_st
tab par_st , gen(d_par_st)

egen idgrade = group(idschool class)

egen school_size = count(idschool) , by(idschool)
egen grade_size = count(idgrade), by(idgrade)

recode H1WP2 (0=1) (1=0) , gen(authoritarian_parents)

egen gpa = rowmean(cogn2 cogn3 cogn4 cogn5) 
egen gpa_peers = rowmean(mean_peer_cogn2   mean_peer_cogn3    mean_peer_cogn4   mean_peer_cogn5)

replace race = 4 if race==.
replace gender = 3 if gender==.


gen family_income_miss = family_income 
qui sum family_income
replace family_income_miss = r(mean) if family_income==.

gen d_family_income_miss = 0
replace d_family_income_miss = 1 if family_income==.

gen educ_mother_miss = .
replace  educ_mother_miss = educ_mother if educ_mother!=.
replace educ_mother_miss = 0 if educ_mother==.

gen d_educ_mother_miss = 0
replace d_educ_mother_miss =1 if educ_mother==.


xtset idschool

egen mean_skills_grade = mean(gpa), by(idgrade) 
egen sd_skills_grade = sd(gpa), by(idgrade) 


global regressors1 "mean_skills_grade "
global regressors2 "sd_skills_grade  "
global regressors3 "mean_skills_grade sd_skills_grade"
global regressors4 "mean_skills_grade "
global regressors5 " sd_skills_grade  "
global regressors6 "mean_skills_grade sd_skills_grade   "

label variable sd_skills_grade "SD GPA within Grade"
label variable mean_skills_grade "Mean GPA within Grade"
label variable grade_size "Grade Size"


global regressors_gender1 "gender#c.mean_skills_grade "
global regressors_gender2 "gender#c.sd_skills_grade  "
global regressors_gender3 "gender#c.(mean_skills_grade sd_skills_grade)"
global regressors_gender4 "gender#c.mean_skills_grade "
global regressors_gender5 " gender#c.sd_skills_grade  "
global regressors_gender6 "gender#c.(mean_skills_grade sd_skills_grade)   "


local ind = 1
foreach x in H1WP1 H1WP2 H1WP3  H1WP6  {
recode `x' (0=1) (1=0), gen(author_proxy`ind')
local ++ind
}

local ind = 1
foreach x in  H2WP1 H2WP2 H2WP3  H2WP6  {
recode `x' (0=1) (1=0), gen(author_proxy`ind'_t2)
local ++ind
}



preserve

*Our Full sample described in Appendix Table A-1;
keep if school_size>=200
keep if class >=9 & class<=12
*Keep main High-Schools in the sample;
keep if  idschool<100 | (idschool>=200 & idschool<300) 

factor author_proxy1 author_proxy2 author_proxy3 author_proxy4  , factors(1)
predict author_factor if e(sample), bartlett
qui sum author_factor, de
replace author_factor = (author_factor-r(mean))/r(sd)

qui reg authoritarian_parents mean_skills_grade sd_skills_grade $controls  , cluster(idschool) 
gen est_sample = e(sample)
xtset idschool

forvalues j = 1(1)6{

if `j'<4{
xtreg authoritarian_parents ${regressors`j'}  if est_sample==1, fe vce(cluster idschool)
est store est_`j'
qui sum authoritarian_parents if e(sample)
qui estadd scalar mean = r(mean)
estadd local cont "No": est_`j'
estadd local s_fe "Yes": est_`j'
}

if `j'>=4{

xtreg authoritarian_parents ${regressors`j'} $controls if est_sample==1, fe vce(cluster idschool)
est store est_`j'
qui sum authoritarian_parents if e(sample)
qui estadd scalar mean = r(mean)
estadd local cont "Yes": est_`j'
estadd local s_fe "Yes": est_`j'
}

}

**************************************************************************************************;
*Table 1: Authoritarian Parenting and Peer Environment within Schools;
**************************************************************************************************;


#delimit ;
esttab est_1 est_2 est_3 est_4 est_5 est_6 , 
nonotes nocons  replace label  
starlevels(* 0.10 ** 0.05 *** 0.01) b(%5.3f) se not keep(mean_skills_grade sd_skills_grade ) order(mean_skills_grade sd_skills_grade )

stats(mean N N_clust cont s_fe , fmt(%9.3f %9.0g %9.0g %s %s) 
 labels("Mean Dependent Var." "Observations" "Clusters" "Controls" "School F.E."))  
prehead( " \begin{tabular}{lcccccc} \hline \hline \\ ")  posthead(" &    \multicolumn{6}{c}{ Authoritarian (Index)}    \\ \hline \\")
 postfoot("\hline \hline \end{tabular}")  
 nomtitles
 ;
#delimit cr;
estimates clear


**************************************************************************************************;
*Appendix Table A-4: Authoritarian Parenting and Peer Environment within Schools (by Gender);
**************************************************************************************************;

xtset idschool

forvalues j = 1(1)6{

if `j'<4{
xtreg authoritarian_parents ${regressors_gender`j'}  if est_sample==1, fe vce(cluster idschool)
est store est_`j'
qui  sum authoritarian_parents if est_sample & gender==1
qui  estadd scalar mean_b = r(mean): est_`j'
qui  sum authoritarian_parents if est_sample & gender==2
qui estadd scalar mean_f = r(mean): est_`j'
estadd local cont "No": est_`j'
estadd local s_fe "Yes": est_`j'
}

if `j'>=4{

xtreg authoritarian_parents ${regressors_gender`j'} $controls if est_sample==1, fe vce(cluster idschool)
est store est_`j'
qui sum authoritarian_parents if est_sample & gender==1
qui estadd scalar mean_b = r(mean): est_`j'
qui sum authoritarian_parents if est_sample & gender==2
qui estadd scalar mean_f = r(mean): est_`j'
estadd local cont "Yes": est_`j'
estadd local s_fe "Yes": est_`j'
}

}


#delimit ;
esttab est_1 est_2 est_3 est_4 est_5 est_6 , 
nonotes nocons  replace label  
starlevels(* 0.10 ** 0.05 *** 0.01) b(%5.3f) se not keep(1.gender#c.mean_skills_grade 2.gender#c.mean_skills_grade 1.gender#c.sd_skills_grade 2.gender#c.sd_skills_grade) order(1.gender#c.mean_skills_grade 2.gender#c.mean_skills_grade 1.gender#c.sd_skills_grade 2.gender#c.sd_skills_grade )
stats(mean_b mean_f N N_clust cont s_fe , fmt(%9.3f %9.3f %9.0g %9.0g %s %s) 
 labels("Mean Dependent Var. (Male)" "Mean Dependent Var. (Female)" "Observations" "Clusters" "Controls" "School F.E."))  
prehead( " \begin{tabular}{lcccccc} \hline \hline \\  ")  posthead(" &    \multicolumn{6}{c}{ Authoritarian}    \\ \hline \\ ")
 postfoot("\hline \hline \end{tabular}")  
 varlabels( 1.gender#c.mean_skills_grade "Male $\times$ Mean GPA within Grade" 2.gender#c.mean_skills_grade "Female $\times$ Mean GPA within Grade" 1.gender#c.sd_skills_grade "Male $\times$ SD GPA within Grade" 2.gender#c.sd_skills_grade "Female $\times$ SD GPA within Grade")   
 nomtitles;
#delimit cr;
estimates clear
drop est_sample



**************************************************************************************************;
*Appendix Table A-5: Authoritarian Parenting (Index) and Peer Environment within Schools
**************************************************************************************************;

qui reg author_factor mean_skills_grade sd_skills_grade $controls  , cluster(idschool) 
gen est_sample = e(sample)
xtset idschool

forvalues j = 1(1)6{

if `j'<4{
xtreg author_factor ${regressors`j'}  if est_sample==1, fe vce(cluster idschool)
est store est_`j'
qui sum authoritarian_parents if e(sample)
qui estadd scalar mean = r(mean)
estadd local cont "No": est_`j'
estadd local s_fe "Yes": est_`j'
}

if `j'>=4{

xtreg author_factor ${regressors`j'} $controls if est_sample==1, fe vce(cluster idschool)
est store est_`j'
qui sum authoritarian_parents if e(sample)
qui estadd scalar mean = r(mean)
estadd local cont "Yes": est_`j'
estadd local s_fe "Yes": est_`j'
}

}

#delimit ;
esttab est_1 est_2 est_3 est_4 est_5 est_6, 
nonotes nocons  replace label  
starlevels(* 0.10 ** 0.05 *** 0.01) b(%5.3f) se not keep(mean_skills_grade sd_skills_grade ) order(mean_skills_grade sd_skills_grade )

stats(mean N N_clust cont s_fe , fmt(%9.3f %9.0g %9.0g %s %s) 
 labels("Mean Dependent Var." "Observations" "Clusters" "Controls" "School F.E."))  
prehead( " \begin{tabular}{lcccccc} \hline \hline \\ ")  posthead(" &    \multicolumn{6}{c}{ Authoritarian (Index)}    \\ \hline \\")
 postfoot("\hline \hline \end{tabular}")  
 nomtitles
 ;
#delimit cr;
estimates clear
drop est_sample


restore




******************************************************************************;
*Appendix Table A-3: Authoritarian Parenting and Peer Environment within Schools (Gini)
******************************************************************************;


preserve

*Our Full sample described in Appendix Table A-1;
keep if school_size>=200
keep if class >=9 & class<=12
*Keep main High-Schools in the sample;
keep if  idschool<100 | (idschool>=200 & idschool<300) 

*Bartlett score for authoritarian parenting;
factor author_proxy1 author_proxy2 author_proxy3 author_proxy4  , factors(1)
predict author_factor if e(sample), bartlett
qui sum author_factor, de
replace author_factor = (author_factor-r(mean))/r(sd)

levelsof idgrade, local(grade_code)
gen gini_gpa = .
foreach c of local grade_code {
ineqdeco gpa if idgrade== `c'
replace gini_gpa = r(gini) if idgrade== `c'
}

qui sum gini_gpa, de
replace gini_gpa = (gini_gpa - r(mean))/r(sd)

label variable gini_gpa "Gini GPA within Grade"


global regressors1 "mean_skills_grade "
global regressors2 "gini_gpa  "
global regressors3 "mean_skills_grade gini_gpa"
global regressors4 "mean_skills_grade "
global regressors5 " gini_gpa  "
global regressors6 "mean_skills_grade gini_gpa  "

qui reg authoritarian_parents mean_skills_grade sd_skills_grade $controls  , cluster(idschool) 
gen est_sample = e(sample)
xtset idschool

forvalues j = 1(1)6{

if `j'<4{
xtreg authoritarian_parents ${regressors`j'}  if est_sample==1, fe vce(cluster idschool)
est store est_`j'
qui sum authoritarian_parents if e(sample)
qui estadd scalar mean = r(mean)
estadd local cont "No": est_`j'
estadd local s_fe "Yes": est_`j'
}

if `j'>=4{

xtreg authoritarian_parents ${regressors`j'}  $controls if est_sample==1, fe vce(cluster idschool)
est store est_`j'
qui sum authoritarian_parents if e(sample)
qui estadd scalar mean = r(mean)
estadd local cont "Yes": est_`j'
estadd local s_fe "Yes": est_`j'
}

}



#delimit ;
esttab est_1 est_2 est_3 est_4 est_5 est_6, 
nonotes nocons  replace label  
starlevels(* 0.10 ** 0.05 *** 0.01) b(%5.3f) se not keep(mean_skills_grade gini_gpa ) order(mean_skills_grade gini_gpa )

stats(mean N N_clust cont s_fe , fmt(%9.3f %9.0g %9.0g %s %s) 
 labels("Mean Dependent Var." "Observations" "Clusters" "Controls" "School F.E."))  
prehead( " \begin{tabular}{lcccccc} \hline \hline \\  ")  posthead(" &    \multicolumn{6}{c}{ Authoritarian}    \\ \hline \\ ")
 postfoot("\hline \hline \end{tabular}")  
 nomtitles
 ;
#delimit cr;

estimates clear
drop est_sample


restore




